package com.zfl.thread.day02;

import java.util.concurrent.*;

public class ThreadPoolService {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,//核心线程数
                5,//最大线程数
                500,//临时线程最大等待时间
                TimeUnit.MICROSECONDS,//上个参数单位
                new ArrayBlockingQueue<>(3),//阻塞队列
                Executors.defaultThreadFactory(),//创建线程的方式
                new ThreadPoolExecutor.DiscardOldestPolicy()//拒绝策略
        );
        for (int i = 0; i < 10; i++) {
            final int N = i;
            pool.execute(()->{
                System.out.println(Thread.currentThread().getName()+"正在执行第"+N+"个任务");
            });
        }
        pool.shutdown();
    }
}
